package com.whu.exp1jsp.controller;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet(name = "signUpServlet", value = "/signUp-servlet")
public class SignUpServlet extends HttpServlet {

    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // 获取表单参数
        String account = request.getParameter("account");
        String password = request.getParameter("password");
        String checkPassword = request.getParameter("checkPassword");
        String code = request.getParameter("code");

        // 假设注册逻辑已经实现，这里简单打印
        System.out.println("账号: " + account);
        System.out.println("密码: " + password);
        System.out.println("确认密码: " + checkPassword);
        System.out.println("验证码: " + code);

        // 注册逻辑
        if (password.equals(checkPassword)) {
            // 注册成功，跳转到登录页面
            request.setAttribute("successMessage", "注册成功");
            request.getRequestDispatcher("login.jsp").forward(request, response);
        } else {
            // 注册失败，返回注册页面并显示错误信息
            request.setAttribute("errorMessage", "密码不匹配");
            request.getRequestDispatcher("login.jsp").forward(request, response);
        }
    }


}
